<?php

class Core_Model_Article_Collection_Comment extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('article/comment');
        $this->from('{t}article_comment', 'a')
                ->select()->field('a.*');
    }

    public function sortBy($name, $dir) {
        switch ($name) {
            case 'time':
                return $dir == 'asc' ? $this->asc("a.time") : $this->desc("a.time");
        }
        return parent::sortBy($name, $dir);
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'articleid':
                return $this->eq('a.article_id', ':article_id:i')->addParameter('article_id', $arg);
            case 'status':
                return $this->eq('a.status', ':status:s')->addParameter('status', $arg);
            case 'ip':
                return $this->eq('a.ip', ':ip:s')->addParameter('ip', $arg);
        }
        return parent::filterBy($name, $arg);
    }
}